﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NET4.Database.Repository;

namespace NET4.DataNET4Postcode.Repository
{
  public class PostcodeRepository : BaseNET4PostcodeRepository<Postcode, PostcodeRepository>, IRepository<Postcode>
  {
    public Postcode Select(Int32 id)
    {
      return this.Table.Where(p => p.Id == id).First();
    }

    public List<Postcode> List()
    {
      return this.Table.ToList();
    }

    public void Save(Postcode postcode)
    {
      if (postcode.Id == 0)
      {
        this.Table.InsertOnSubmit(postcode);
      }

      this.DataContext.SubmitChanges();
    }

    public void Delete(Postcode postcode)
    {
      this.Table.DeleteOnSubmit(postcode);

      this.DataContext.SubmitChanges();
    }

    public Postcode SelectByZipCode(String zipCode)
    {
      return this.Table.Where(p => p.Postcode1 == zipCode).First();
    }
  }
}
